package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/12/4 10:18
 * @description：https://leetcode-cn.com/problems/ransom-note/
 */
public class 赎金信 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.canConstruct("aa", "aab"));
    }

    class Solution {
        public boolean canConstruct(String ransomNote, String magazine) {
            int[] counts = new int[26];
            for (int i = 0; i < magazine.length(); i++) {
                counts[magazine.charAt(i) - 'a']++;
            }
            for (int i = 0; i < ransomNote.length(); i++) {
                if(counts[ransomNote.charAt(i) - 'a']-- < 0) {
                    return false;
                }
            }
            return true;
        }
    }
}
